package com.yiwei.hdb.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.yiwei.hdb.R;
import com.yiwei.hdb.adapter.V3IdentityInfoPhotoAdapter;
import com.yiwei.hdb.adapter.V3IdentityInfoSuccessAdapter;
import com.yiwei.hdb.api.Api;
import com.yiwei.hdb.api.bean.CertificationDetailBean;
import com.yiwei.hdb.constant.Const;
import com.yiwei.hdb.constant.UserGlobal;
import com.yiwei.hdb.model.CertificationDetailModel;
import com.yiwei.hdb.util.Network;
import com.yiwei.hdb.util.PreferenceUtils;
import com.yiwei.hdb.util.RxLifeUtil;
import com.yiwei.hdb.util.ToastUtil;
import com.yiwei.hdb.util.Util;
import com.yiwei.hdb.view.V19FrameLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import kangcheng.com.lmzx_android_sdk_v10.bean.Fuction;
import kangcheng.com.lmzx_android_sdk_v10.commom.sdk.LmzxSdkImpl;

/**
 * Created by Administrator on 2018/6/10.
 */

public class V3IdentitySuccessInfoActivity extends BaseActivity {
    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_right)
    TextView txtRight;
    @BindView(R.id.layout_title)
    V19FrameLayout layoutTitle;
    @BindView(R.id.img_type)
    ImageView imgType;
    @BindView(R.id.txt_type)
    TextView txtType;
    @BindView(R.id.list_photo)
    RecyclerView listPhoto;
    @BindView(R.id.list)
    RecyclerView list;
    @BindView(R.id.img_bg_color)
    SuperButton imgBgColor;
    private Unbinder unbinder;
    private V3IdentityInfoSuccessAdapter v3IdentityInfoSuccessAdapter;
    private V3IdentityInfoPhotoAdapter photoAdapter;
    private int[] shenfen = new int[]{0xff97A3FC, 0xff5A89FF, R.mipmap.img_type_shenfen};
    private int[] xuexin = new int[]{0xffFE7E6F, 0xffFB494F, R.mipmap.img_type_xuexin};
    private int[] tongxun = new int[]{0xff31E597, 0xff1ED184, R.mipmap.img_type_tongxin};
    private int[] taobao = new int[]{0xffFEA853, 0xffF75221, R.mipmap.img_type_taobao};
    private int[] basic = new int[]{0xff97A3FC, 0xff5A89FF, R.mipmap.img_type_basic};
    private int[] zhima = new int[]{0xff31E597, 0xff1ED184, R.mipmap.img_type_zhima};
    private int[] jingdong = new int[]{0xffFE7E6F, 0xffFB494F, R.mipmap.img_type_jingdong};
    private int[] email = new int[]{0xffFEA853, 0xffF75221, R.mipmap.img_type_email};
    private int[] income = new int[]{0xff31E597, 0xff1ED184, R.mipmap.img_type_income};
    private int[] shebao = new int[]{0xff97A3FC, 0xff5A89FF, R.mipmap.img_type_shebao};
    private int[] gongjijin = new int[]{0xff31E597, 0xff1ED184, R.mipmap.img_type_gongjijin};
    private int[] car = new int[]{0xffFE7E6F, 0xffFB494F, R.mipmap.img_type_car};
    private int[] work = new int[]{0xffFEA853, 0xffF75221, R.mipmap.img_type_work};
    private int[] house = new int[]{0xff97A3FC, 0xff5A89FF, R.mipmap.img_type_house};
    private int[] link = new int[]{0xff31E597, 0xff1ED184, R.mipmap.img_type_link};
    private int[] bankcard = new int[]{0xffFE7E6F, 0xffFB494F, R.mipmap.img_type_bankcard};
    private String remark;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_identity_info_success);
        initBar();
        unbinder = ButterKnife.bind(this);
        init();
    }

    private void init() {
        remark = getIntent().getStringExtra("remark");
        txtTitle.setText("");
        getCertificationDetails(remark);


//
        v3IdentityInfoSuccessAdapter = new V3IdentityInfoSuccessAdapter(this);
        list.setAdapter(v3IdentityInfoSuccessAdapter);
        photoAdapter = new V3IdentityInfoPhotoAdapter(this);
        listPhoto.setAdapter(photoAdapter);

        listPhoto.setNestedScrollingEnabled(false);
        list.setNestedScrollingEnabled(false);
    }


    public void getCertificationDetails(String remark) {
        if (!Network.checkNetwork(this)) {
            ToastUtil.makeText(this, "网络连接失败");
            return;
        }

        loadingDialog.show();
        CertificationDetailBean bean = new CertificationDetailBean();
        bean.remark = remark;
        Api.api_service.getCertificationDetails(bean).compose(RxLifeUtil.checkOn(this)).
                doFinally(() -> {
                    try {
                        loadingDialog.dismiss();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    setData(result.data);
                });
    }

    private void setData(CertificationDetailModel.DataBean data) {
        if (data.isVerify == 0) {
            ToastUtil.makeText(this, "尚未完成该认证");
            return;
        }
        switch (remark) {
            case Const.IdentityType.yunyin:
                txtTitle.setText("通讯认证");
                txtType.setText("通讯认证已通过");
                imgType.setImageResource(tongxun[2]);
                imgBgColor.setShapeGradientStartColor(tongxun[0]).setShapeGradientEndColor(tongxun[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;
            case Const.IdentityType.car:
                txtTitle.setText("车产认证");
                txtType.setText("车产认证已认证");
                imgType.setImageResource(car[2]);
                imgBgColor.setShapeGradientStartColor(car[0]).setShapeGradientEndColor(car[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;
            case Const.IdentityType.contacts:
                txtTitle.setText("基础认证");
                txtType.setText("基础认证已通过");
                imgType.setImageResource(basic[2]);
                imgBgColor.setShapeGradientStartColor(basic[0]).setShapeGradientEndColor(basic[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;

            case Const.IdentityType.email:
                txtTitle.setText("邮箱认证");
                txtType.setText("邮箱认证已通过");
                imgType.setImageResource(email[2]);
                imgBgColor.setShapeGradientStartColor(email[0]).setShapeGradientEndColor(email[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;

            case Const.IdentityType.face_detect:
                txtTitle.setText("芝麻认证");
                txtType.setText("芝麻认证已通过");
                imgType.setImageResource(zhima[2]);
                imgBgColor.setShapeGradientStartColor(zhima[0]).setShapeGradientEndColor(zhima[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;

            case Const.IdentityType.house:
                txtTitle.setText("房产认证");
                txtType.setText("房产认证已认证");
                imgType.setImageResource(house[2]);
                imgBgColor.setShapeGradientStartColor(house[0]).setShapeGradientEndColor(house[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;

            case Const.IdentityType.housefund:
                txtTitle.setText("公积金认证");
                txtType.setText("公积金认证已认证");
                imgType.setImageResource(gongjijin[2]);
                imgBgColor.setShapeGradientStartColor(gongjijin[0]).setShapeGradientEndColor(gongjijin[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;

            case Const.IdentityType.income:
                txtTitle.setText("收入证明");
                txtType.setText("收入证明已认证");
                imgType.setImageResource(income[2]);
                imgBgColor.setShapeGradientStartColor(income[0]).setShapeGradientEndColor(income[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;

            case Const.IdentityType.jd:
                txtTitle.setText("京东认证");
                txtType.setText("京东认证已通过");
                imgType.setImageResource(jingdong[2]);
                imgBgColor.setShapeGradientStartColor(jingdong[0]).setShapeGradientEndColor(jingdong[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;
            case Const.IdentityType.linkedin:
                txtTitle.setText("领英认证");
                txtType.setText("领英认证已认证");
                imgType.setImageResource(link[2]);
                imgBgColor.setShapeGradientStartColor(link[0]).setShapeGradientEndColor(link[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;

            case Const.IdentityType.realname:
                txtTitle.setText("身份认证");
                txtType.setText("身份认证已通过");
                imgType.setImageResource(shenfen[2]);
                imgBgColor.setShapeGradientStartColor(shenfen[0]).setShapeGradientEndColor(shenfen[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;

            case Const.IdentityType.socialsecurity:
                txtTitle.setText("社保认证");
                txtType.setText("社保认证已认证");
                imgType.setImageResource(shebao[2]);
                imgBgColor.setShapeGradientStartColor(shebao[0]).setShapeGradientEndColor(shebao[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;

            case Const.IdentityType.taobao:
                txtTitle.setText("淘宝认证");
                txtType.setText("淘宝认证已通过");
                imgType.setImageResource(taobao[2]);
                imgBgColor.setShapeGradientStartColor(taobao[0]).setShapeGradientEndColor(taobao[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;
            case Const.IdentityType.work:
                txtTitle.setText("工作证明");
                txtType.setText("工作证明已认证");
                imgType.setImageResource(work[2]);
                imgBgColor.setShapeGradientStartColor(work[0]).setShapeGradientEndColor(work[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;
            case Const.IdentityType.xuexin:
                txtTitle.setText("学信网认证");
                txtType.setText("学信网认证已通过");
                imgType.setImageResource(xuexin[2]);
                imgBgColor.setShapeGradientStartColor(xuexin[0]).setShapeGradientEndColor(xuexin[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;
            case Const.IdentityType.bankcard:
                txtTitle.setText("银行卡认证");
                txtType.setText("银行卡认证已通过");
                imgType.setImageResource(bankcard[2]);
                imgBgColor.setShapeGradientStartColor(bankcard[0]).setShapeGradientEndColor(bankcard[1]).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
                break;

        }

        if (data.images != null && data.images.size() != 0) {
            photoAdapter.update(data.images);
        } else {
            listPhoto.setVisibility(View.GONE);
        }
        if (data.items != null && data.items.size() != 0) {
            v3IdentityInfoSuccessAdapter.update(data.items);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
        unbinder = null;
    }

    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }
}
